from rest_framework.serializers import ModelSerializer, SerializerMethodField
from iot.models import Point, Cabinet


class CabinetSerializer(ModelSerializer):
    cabinetId = SerializerMethodField()

    def get_cabinetId(self, instance):
        return instance.id

    class Meta:
        model = Cabinet
        fields = ('name', 'cabinetId')


class PointSerializer(ModelSerializer):
    name = SerializerMethodField()
    pointCode = SerializerMethodField()

    def get_name(self, instance: Point):
        return instance.name

    def get_pointCode(self, instance: Point):
        return instance.code

    class Meta:
        model = Point
        fields = ('name', 'pointCode')
